<?php
header('Content-type:text/html;charset=utf-8');
//ibcurl以外，至少还关联的库包括：libidn,ibgcc,libiconv,libintl,openssl
	
/**
  * 本类代码运行在PHP5.0基础上说明：
  * 1)演示PHP代码访问安徽一拓通信集团有限公司WEBService
  * 2)本类没有实现WEBService所有接口，如需要，请自行参考代码
  * 3)本类所以接口方法均返回simplexml对象，对象结构请参考服务接口文档
  * 4)本类使用扩展SoapClient模块，请确保您的服务器扩展已经包含该模块( php.ini:已经打开 extension=php_soap.dll )
    header('Content-type:text/html;charset=utf-8');
  */	
class Smsclient
{
	var $endpoint;
	private static $_instance;
	private $user="";
	private $password="";
	private $smskinid="";
	private $suffix="";
	
	/**
	 *构造函数
	 *@param wsdl WEB服务地址,此处固定:http://sdk.zyer.cn/SmsService/SmsService.asmx?Wsdl
 	 */	
	function Smsclient()
	{
		$conf=load_conf("sms");
		foreach($conf as $k=>$v){
			$this->$k=$v;
		}
	}

	static function get_instance(){
		if(!(self::$_instance instanceof self)){
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	function send_sms($phone='',$message=''){
		$result=$this->SendEx($this->user,$this->password,$this->smskind,$phone,"",$message.$this->suffix);
		if($result->Code==0){
			return true;
		}

	    return false;
	 }
	function digester($password)
	{
		return substr(md5($password),8,16); 
	}
	
	/**
	 *功能说明：获取账户余额
	 *@param LoginName 登录名
	 *@param Password  登录密码
	 *@param SmsKind  这里固定为808
	 *@return simplexml
 	 */
	function GetBalance($LoginName,$Password,$SmsKind)
	{
		$param=array(   
	    'LoginName'       => $LoginName,   
	    'Password'       => $this->digester($Password),   
	    'SmsKind' => $SmsKind
	   ); 
		
		$soap = new SoapClient($this->endpoint,array('encoding'=>'UTF-8'));  
  	    $result = $soap->GetBalance($param);
		
		return simplexml_load_string($result->GetBalanceResult->any);
	}
	
	
	/**
	 *功能说明：发送短信
	 *@param LoginName 登录名
	 *@param Password  登录密码
	 *@param SmsKind  这里固定为808
	 *@param SendSim  发送手机号
	 *@param ExpSmsId 扩展号
	 *@param MsgContext 短信内容	 
	 *@return simplexml
 	 */
	function SendEx($LoginName,$Password,$SmsKind,$SendSim,$ExpSmsId,$MsgContext)
	{
		$param=array(   
	    'LoginName'       => $LoginName,   
	    'Password'       => $this->digester($Password),   
	    'SmsKind' => $SmsKind,
	    'SendSim'=> $SendSim,	
	    'ExpSmsId'=> $ExpSmsId,
	    'MsgContext'=> $MsgContext	
	   ); 
		
		$soap = new SoapClient($this->endpoint,array('encoding'=>'UTF-8'));  
  	    $result = $soap->SendEx($param);
		return simplexml_load_string($result->SendExResult->any);
	}
	
	
	/**
	 *功能说明：修改密码
	 *@param LoginName 登录名
	 *@param OldPassword  登录密码
	 *@param NewPassword 
	 *@return simplexml
 	 */
	function SetPassword($LoginName,$OldPassword,$NewPassword)
	{
		$param=array(   
	    'LoginName'       => $LoginName,   
	    'OldPassword'       => $this->digester($OldPassword),   
	    'NewPassword'  => $this->digester($NewPassword)
	   ); 
		
		$soap = new SoapClient($this->endpoint,array('encoding'=>'UTF-8'));  
  	    $result = $soap->SetPassword($param);
		
		return simplexml_load_string($result->SetPasswordResult->any);
	}
	
	
	/**
	 *功能说明：获取上行短信
	 *@param LoginName 登录名
	 *@param Password  登录密码
	 *@param SmsKind  这里固定为808
	 *@return simplexml
 	 */
	function GetMo($LoginName,$Password,$SmsKind)
	{
		$param=array(   
	    'LoginName'       => $LoginName,   
	    'Password'       => $this->digester($Password),   
	    'SmsKind' => $SmsKind
	   ); 
		
		$soap = new SoapClient($this->endpoint,array('encoding'=>'UTF-8'));  
  	    $result = $soap->GetMo($param);
		
		return simplexml_load_string($result->GetMoResult->any);
	}
	
	//其它的可以参考WEBService文档参照示例来写
}
?>